<template>
<el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dept">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
            <el-form-item>
                <el-select v-model="dataForm.status" placeholder="请选择状态" clearable>
                    <el-option label="正常" :value="1">
                    </el-option>
                    <el-option label="黑名单" :value="0">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item >
                <el-input v-model="dataForm.userName" placeholder="姓名"></el-input>
            </el-form-item>
            <el-form-item label="">
                <el-input v-model="dataForm.userPhone" placeholder="手机号"></el-input>
            </el-form-item>
            <el-form-item label="">
                <el-input v-model="dataForm.userAge" placeholder="年龄"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="getDataList()">{{ $t('query') }}</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
            <el-table-column prop="userName" label="姓名" align="center" min-width="120"></el-table-column>
            <el-table-column prop="userPhone" label="联系方式" align="center" min-width="120">
            </el-table-column>
            <el-table-column prop="userAge" label="年龄" min-width="120px" align="center"></el-table-column>

            <el-table-column prop="status" label="状态" align="center" width="150px">
                <template slot-scope="scope">
                    <template v-if="scope.row.status==1">
                        <el-button :type="scope.row.status!=1?'info':'success'" size="mini"> {{scope.row.status==0?'黑名单':'正常'}}</el-button>
                    </template>
                    <el-popover v-if="scope.row.status==0" trigger="hover" placement="bottom">
                        <p>原因: {{ scope.row.blackReason }}</p>
                        <div slot="reference" class="name-wrapper">
                            <el-button :type="scope.row.status!=1?'info':'success'" size="mini"> {{scope.row.status==0?'黑名单':'正常'}}</el-button>
                        </div>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="userCode" label="个人标识码" :show-overflow-tooltip="true" align="center" min-width="150px"></el-table-column>
            <el-table-column :label="$t('handle')" fixed="right" align="center" min-width="120">
                <template slot-scope="scope">
                    <el-button type="text" v-if="scope.row.status==1&&$hasPermission('ocp:um:update')" size="small" @click="checkData(scope.row.id,0)">加入黑名单</el-button>
                    <el-button type="text" v-if="scope.row.status==0&&$hasPermission('ocp:um:update')" size="small" @click="checkData(scope.row.id,1)">移除黑名单</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 审核 -->
        <el-dialog title="审核" :visible.sync="dialogFormVisible">
            <el-form :model="check">
                <el-form-item label="拉黑原因" label-width="120px">
                    <el-input v-model="check.blackReason" placeholder="请输入"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmCheck()">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
    mixins: [mixinViewModule],
    data() {
        return {
            mixinViewModuleOptions: {
                getDataListURL: "/order/ocpUm/page",
                getDataListIsPage: true,
            },
            dialogFormVisible: false,
            check: {
                state: '',
                id: '',
            },
            dataForm: {
                status: '',
                userAge: '',
                userName: '',
                userPhone: ''
            },
        };
    },
    components: {},
    methods: {
        checkData(id, status) {
            this.check.status = status
            this.check.id = id;
            if (status == 0) {
                this.dialogFormVisible = true;
            } else {
                this.confirmCheck();
            }
        },
        confirmCheck(status) {
            this.$http
                .put("/order/ocpUm", this.check)
                .then((res) => {
                    if (res.data.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.dialogFormVisible = false;
                    this.$message({
                        message: '操作成功',
                        type: "success",
                        duration: 500,
                        onClose: () => {
                            this.dialogFormVisible = false;
                            this.getDataList();
                        },
                    });
                });
        },
    }
};
</script>
